/**
 * 
 */
package com.jinmei.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.dao.DataAccessException;

import com.jinmei.dao.WorkScheduleSettingDao;
import com.jinmei.model.WorkScheduleSetting;
import com.jinmei.service.WorkScheduleSettingService;

/**
 * @author richard
 *
 */
public class WorkScheduleSettingServiceImpl implements
		WorkScheduleSettingService {
	
	private WorkScheduleSettingDao workScheduleSettingDao;

	public WorkScheduleSettingDao getWorkScheduleSettingDao() {
		return workScheduleSettingDao;
	}

	public void setWorkScheduleSettingDao(
			WorkScheduleSettingDao workScheduleSettingDao) {
		this.workScheduleSettingDao = workScheduleSettingDao;
	}

	@Override
	public void saveOrUpdate(List<WorkScheduleSetting> entities)
			throws DataAccessException {
		getWorkScheduleSettingDao().saveOrUpdate(entities);
	}

	@Override
	public List<WorkScheduleSetting> loadAll() throws DataAccessException {
		List<WorkScheduleSetting> results = getWorkScheduleSettingDao().loadAll();
		if (results == null || results.size() == 0) {
			results = createNewSettings();
		}
		
		return results;
	}
	
	private List<WorkScheduleSetting> createNewSettings() {
		List<WorkScheduleSetting> settings = new ArrayList<WorkScheduleSetting>();
		
		WorkScheduleSetting set1 = new WorkScheduleSetting();
		set1.setWorkingType(0);
		set1.setDescr("A");
		
		WorkScheduleSetting set2 = new WorkScheduleSetting();
		set2.setWorkingType(1);
		set2.setDescr("B");
		
		WorkScheduleSetting set3 = new WorkScheduleSetting();
		set3.setWorkingType(2);
		set3.setDescr("C");
		
		settings.add(set1);
		settings.add(set2);
		settings.add(set3);
		
		return settings;
	}

}
